var dialog = {
    o: null,
    editor: null,
    viewer:null,
    resize: function () {
        var $w = $(window);
        dialog.o.height($w.height() - 200);
        dialog.o.css({
            left: ($w.width() - dialog.o.width()) / 2
        });
    },
    md: '',
    dom: ''
};

$(document).ready(function () {

    dialog.o = $('.main');
    dialog.editor = $('textarea');
    dialog.viewer = $('.right-box');

    dialog.editor.val(unescape(document.cookie).replace(/Tr&@inahoo-enter/g,'\n'));
    dialog.resize();
    setInterval(Trans,500);
});

var Trans = function () {
    var t = new Date().getTime();
    if (dialog.md == dialog.editor.val())return;

    dialog.md = dialog.editor.val();
    document.cookie = escape(dialog.md.replace(/\n/g,'Tr&@inahoo-enter'));

    dialog.dom = markdown.toHTML(dialog.md);
    dialog.viewer.html(dialog.dom);
    console.log(escape(dialog.md.replace(/\n/g,'Tr&@inahoo-enter')));
    console.log(new Date().getTime()-t);
};